<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <form action="">
        <form>
            <div>
                <label for="username">用户名:</label>
                <input type="text" id="username" value="">
            </div>
            <div>
                <label for="pwd">密码:</label>
                <input type="password" id="pwd">
            </div>
            <div>
                <label>性别：</label>
                <label for="male">男</label>
                <input type="radio" id="male" name="gender" value="男">
                <label for="fmale">女</label>
                <input type="radio" id="fmale" name="gender" value="女">
            </div>
            <div>
                <label>爱好：</label>
                <label for="game">游戏</label>
                <input type="checkbox" id="game" name="fav" value="游戏">
                <label for="girl">美女</label>
                <input type="checkbox" id="girl" name="fav" value="美女">
                <label for="sing">唱歌</label>
                <input type="checkbox" id="sing" name="fav" value="唱歌">
            </div>
            <button id="submit">注册</button>
        </form>
    </form>
    <script>
        const submitEle = document.getElementById('submit')
        //对象里面的键和id对应

        function getFormData() {
            let userData = {
                username: '',
                pwd: '',
            }
            for (let key in userData) {
                const ipt = document.getElementById(key)
                console.log(ipt)
                userData[key] = ipt.value
            }
            return userData
        }
        submitEle.onclick = function (e) {
            e.preventDefault()
            let data = getFormData()
            console.log(data)
        }

        let x = {
            x:1,
            y:2,
            z:3
        }
        let a1 = [2,3,4,56]
        // for(let hh in x){
        //     console.log(hh)
        // }
        for(let i in a1){
            console.log(i)
        }
        
    </script>
</body>

</html>